home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
exec.arc
/
EF.C
next >
Wrap
Text File
|
1985-05-28
|
1KB
|
64 lines
/* ef.c execute a list of commands in a file
demo of the fork/execf functions for CI-C86 2.0+
usage: ef filename.ext filename.ext should contain
a list of commands just like
a batch file
!copyrighted by James Montebello.
*/
#include <stdio.h>
main(ac,av)
int ac;
char *av[];
{
char *name;
char cmdl[255];
char *sp;
FILE *fp;
int status;
if (!(fp=fopen(av[1],"r"))) {
printf("ef: error reading file %s\n",av[1]);
exit(1);
}
sp = alloc(255);
while (getline(sp,fp)) {
if (blankline(sp)) continue; /* line blank? skip it */
printf("\n%s\n",sp);
if (fork(sp)) { /* launch the command */
printf("ef: error on line %s\n",sp); /* return non-zero, err */
exit(1);
}
}
}
getline(s,fp) /* gets a \n termed line from fp, rets NULL at EOF */
char s[];
FILE *fp;
{
int i;
char c;
i = 0;
while ((c=getc(fp)) != EOF) {
s[i++] = c;
if (c == '\n')
break;
}
s[i-1] = '\0'; /* don't want the \n in the line */
return(i);
}
blankline(s) /* rets TRUE if line is all whitespace */
char *s;
{
while(*s) {
if (!isspace(*s++)) return 0; /* found something, blast out */
}
return -1; /* its empty */
}